home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Mousebroken 1.0.1 / source / Mousebroken source ƒ / init code / really notify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  3.1 KB  |  136 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        really notify.c
  4.  
  5. Purpose:    This module handles notifying the user that an error has
  6.             occurred (through the Notification Manager); also, displaying
  7.             the proper icon during init loading.
  8.             
  9.  
  10. Mousebroken -=- your computer isn't truly broken until it's mousebroken
  11. Copyright (C) 1993 Mark Pilgrim
  12.  
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program in a file named "GNU General Public License".
  25. If not, write to the Free Software Foundation, 675 Mass Ave,
  26. Cambridge, MA 02139, USA.
  27.  
  28. \**********************************************************************/
  29.  
  30. #include "structs.h"
  31. #include "really notify.h"
  32. #include "show init.h"
  33. #include "GestaltEQU.h"
  34.  
  35. #define        DEFAULT_MESSAGE        "\pMousebroken did not open because \
  36. an error occurred during startup.  The INIT may be damaged, \
  37. or there may not be enough memory in the system heap."
  38.  
  39. void StartupError(int errorcode)
  40. {
  41.     Str255            errorText;
  42.     Str255            errorNumber;
  43.     unsigned char    *defaultText = DEFAULT_MESSAGE;
  44.     unsigned char    *textPtr;
  45.     StringPtr        str;
  46.     int                size;
  47.     Boolean            gHasNotification;
  48.     OSErr            isHuman;
  49.     unsigned long    gestalt_temp;
  50.     
  51.     isHuman = Gestalt(gestaltNotificationMgrAttr, &gestalt_temp);
  52.     gHasNotification=((!isHuman) &&
  53.         (((gestalt_temp >> gestaltNotificationPresent) & 0x01) == 1));
  54.     if (gHasNotification)
  55.     {
  56.         SetZone(ApplZone);
  57.         GetIndString(errorText, STARTUP_ERROR_STR, errorcode);
  58.         SetZone(SysZone);
  59.         textPtr=(errorText[0]==0) ? defaultText : errorText;        
  60.         size = textPtr[0] + 1;
  61.         str = (StringPtr)NewPtrSys(size);
  62.         if(str)
  63.         {
  64.             BlockMove(textPtr, str, size);
  65.             
  66.             if(SetupNM(str))
  67.                 DisposePtr(str);
  68.         }
  69.     }
  70.     
  71.     SetZone(ApplZone);
  72.     ShowBadICON();
  73.     SetZone(SysZone);
  74. }
  75.  
  76. void StartupGood(PrefHandle cdevStorage)
  77. {
  78.     if ((**cdevStorage).showIcon)
  79.     {
  80.         SetZone(ApplZone);
  81.         ShowGoodICON();
  82.         SetZone(SysZone);
  83.     }
  84. }
  85.  
  86. int SetupNM(StringPtr str)
  87. {
  88.     NMRec            *note;
  89.     Handle            nmResponse;
  90.     OSErr            isHuman;
  91.     long            gestaltReturn;
  92.     
  93.     if(str == (StringPtr)0L)
  94.         return 1;
  95.     
  96.     note = (NMRec*)NewPtrSys(sizeof(NMRec));
  97.     if(!note)
  98.     {
  99.         return 1;
  100.     }
  101.     else
  102.     {
  103.         note->qType = nmType;
  104.         note->nmMark = 0;
  105.         note->nmIcon = 0L;
  106.         note->nmSound = 0L;
  107.         note->nmStr = str;
  108.         
  109.         /* NMRP ID=RESPONSE_NMRP must be System Heap, Preload */
  110.         nmResponse = GetResource('NMRP', RESPONSE_NMRP);
  111.         if(!nmResponse)
  112.         {
  113.             DisposePtr(note);
  114.             return 1;
  115.         }
  116.         else
  117.         {
  118.             HLock(nmResponse);
  119.             HNoPurge(nmResponse);
  120.             DetachResource(nmResponse);
  121.             
  122.             note->nmResp = (ProcPtr)*nmResponse;
  123.             
  124.             if(NMInstall(note) == noErr)
  125.             {
  126.                 return 0;
  127.             }
  128.             else
  129.             {
  130.                 DisposePtr(note);
  131.                 return 1;
  132.             }
  133.         }
  134.     }
  135. }
  136.